package org.bsuir.filespocket.view;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.bsuir.filespocket.service.UserDAO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteUserController implements Controller {

    private UserDAO userDAO;

    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse httpServletResponse)
            throws Exception {
        int userId;
        try {
            userId = Integer.parseInt(request.getParameter("userId"));
        } catch (Exception e) {
            userId = -1;//TODO return some error message
        }
        userDAO.deleteUser(userId);
        return new ModelAndView(new RedirectView("userList.html"));
    }
}
